package cn.iocoder.yudao.hires.controller.admin.notice;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.hires.entity.NoticeEnterpriseDO;
import cn.iocoder.yudao.hires.service.notice.NoticeEnterpriseService;
import cn.iocoder.yudao.hires.vo.noticeenterprise.NoticeEnterprisePageReqVO;
import cn.iocoder.yudao.hires.vo.noticeenterprise.NoticeEnterpriseRespVO;
import cn.iocoder.yudao.hires.vo.noticeenterprise.NoticeEnterpriseSaveReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 下游-企业人才库")
@RestController
@RequestMapping("/system/notice-enterprise")
@Validated
public class NoticeEnterpriseController {

    @Resource
    private NoticeEnterpriseService noticeEnterpriseService;

    @PostMapping("/create")
    @Operation(summary = "创建下游-企业人才库")
    //@PreAuthorize("@ss.hasPermission('system:notice-enterprise:create')")
    public CommonResult<Long> createNoticeEnterprise(@Valid @RequestBody NoticeEnterpriseSaveReqVO createReqVO) {
        return success(noticeEnterpriseService.createNoticeEnterprise(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新下游-企业人才库")
    //@PreAuthorize("@ss.hasPermission('system:notice-enterprise:update')")
    public CommonResult<Boolean> updateNoticeEnterprise(@Valid @RequestBody NoticeEnterpriseSaveReqVO updateReqVO) {
        noticeEnterpriseService.updateNoticeEnterprise(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除下游-企业人才库")
    @Parameter(name = "id", description = "编号", required = true)
    //@PreAuthorize("@ss.hasPermission('system:notice-enterprise:delete')")
    public CommonResult<Boolean> deleteNoticeEnterprise(@RequestParam("id") Long id) {
        noticeEnterpriseService.deleteNoticeEnterprise(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得下游-企业人才库")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    //@PreAuthorize("@ss.hasPermission('system:notice-enterprise:query')")
    public CommonResult<NoticeEnterpriseRespVO> getNoticeEnterprise(@RequestParam("id") Long id) {
        NoticeEnterpriseDO noticeEnterprise = noticeEnterpriseService.getNoticeEnterprise(id);
        return success(BeanUtils.toBean(noticeEnterprise, NoticeEnterpriseRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得下游-企业人才库分页")
    //@PreAuthorize("@ss.hasPermission('system:notice-enterprise:query')")
    public CommonResult<PageResult<NoticeEnterpriseRespVO>> getNoticeEnterprisePage(@Valid NoticeEnterprisePageReqVO pageReqVO) {
        PageResult<NoticeEnterpriseDO> pageResult = noticeEnterpriseService.getNoticeEnterprisePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, NoticeEnterpriseRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出下游-企业人才库 Excel")
    //@PreAuthorize("@ss.hasPermission('system:notice-enterprise:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportNoticeEnterpriseExcel(@Valid NoticeEnterprisePageReqVO pageReqVO, HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<NoticeEnterpriseDO> list = noticeEnterpriseService.getNoticeEnterprisePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "下游-企业人才库.xls", "数据", NoticeEnterpriseRespVO.class, BeanUtils.toBean(list, NoticeEnterpriseRespVO.class));
    }

}